package com.sam.thread.demo3;

/**
 * Hello world!
 */
public class DeadLock implements Runnable {
    private int i = 0;
    @Override
    public void run() {
        while (true){
            if(i%2 == 0){
                //先进入A同步 再进入B同步
                synchronized (LockA.lock){
                    System.out.println("if  locka...i:"+ i );
                    synchronized (LockB.lock){
                        System.out.println("if  lockb...i:"+ i );

                    }
                }
            }else{
                //先进入B同步 再进入A同步
                synchronized (LockB.lock){
                    System.out.println("if  lockb...i:"+ i );
                    synchronized (LockA.lock){
                        System.out.println("if  locka...i:"+ i );
                    }
                }
            }
            i++;
        }
    }
}
